//
//  MyEndEnquiryTbv.m
//  ZITHER
//
//  Created by weixin on 2018/10/17.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "MyEndEnquiryTbv.h"
#import "MyEnquiryEndListNewModel.h"
#import "STViewController.h"
#import "MeBizQutoeCell.h"

@interface MyEndEnquiryTbv ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)NSMutableArray <MyEnquiryListDataEndNewModel*>* arrM;

@end

@implementation MyEndEnquiryTbv

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self defaultConfiguration];
        [self loadData];
    }
    return self;
}

- (void)Starefreshing{
    [self loadData];
}

-(void)loadData{
    
    //已结束询价
    [[serviceDefualt loadgetMyEndEnquiryList:self.page reponseObjctClass:nil]subscribeNext:^(ResponseData *  x) {
        
                    if (x.success) {
                        NSArray *arr = x.responseRawData[@"data"];
                        
                        if (arr.count == 0 ) {
                            if (self.page == 0) {
                                [Tools showTips:@"暂无更多数据"];
                                [self endRefreshing];
                            }else{
                                [self.mj_footer endRefreshingWithNoMoreData];
                            }
                            return ;
                        }
                        if (self.page == 0) {
                            [self.mj_footer resetNoMoreData];
                            self.arrM = [[NSMutableArray alloc]init];
                        }
                        for (NSDictionary *dic in x.responseRawData[@"data"]) {
                            
                            MyEnquiryListDataEndNewModel *model = [MyEnquiryListDataEndNewModel yy_modelWithDictionary:dic];
                            [self.arrM addObject:model];
                        }
                    }else{
                        if (![x.errorInfo isEqualToString:@"未登录"]) {
                             [Tools showTips:x.errorInfo];
                        }
                    }
                    [self endRefreshing];
                    [self reloadData];
        
    }];
    

    
    
}

-(void)defaultConfiguration{
    self.delegate = self;
    self.dataSource = self;
    
    }

#pragma mark -- tabdelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arrM.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    
    static NSString *sectionCell = @"MeBizQutoeCell";
    
    MeBizQutoeCell *cell = [tableView dequeueReusableCellWithIdentifier:sectionCell];
    
    if (cell == nil) {
        cell = [[MeBizQutoeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
    }
    
    cell.selectionStyle = UITableViewCellSeparatorStyleNone;
    
    [cell setBizQutoeType:BizQutoeCellBtnTips];
    cell.modeTyep2 = self.arrM[indexPath.row];

//    if (indexPath.row == self.model.data.count+1 && self.arrMEndData.count!=0) {
//        [cell setBizQutoeType:BizQutoeCellREnd];
//    }else{
//        [cell setBizQutoeType:BizQutoeCellDef];
//        cell.modeTyep1 = self.model.data[indexPath.row-1];
//    }
    return cell;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    STViewController *vc = [[STViewController alloc]init];
    vc.type = STControllerTypeHiddenNavBar;
    vc.goodId = self.arrM[indexPath.row].goodsId;
    [self.getNav pushViewController:vc animated:YES];
    
}

-(NSMutableArray *)arrM{
    if (!_arrM) {
        _arrM = [[NSMutableArray alloc]init];

    }
        return _arrM;
}

@end
